﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class BalanceCenter_AdminNewsAdd : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Request.QueryString["NewType"] != null)
            {
                this.ViewState["NewType"] = Request.QueryString["NewType"].ToString();
                if (ViewState["NewType"].ToString() == "1")
                {
                    this.lblInfo.Text = "编辑新闻信息";
                }

                if (ViewState["NewType"].ToString() == "2")
                {
                    this.lblInfo.Text = "编辑优惠活动信息";
                }

                if (ViewState["NewType"].ToString() == "3")
                {
                    this.lblInfo.Text = "编辑培训新闻信息";
                }
            }

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.FillContent, Competences.EditNews);
        RequestLoginPage = "BalanceCenter/AdminNewsAdd.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        tbDateTime.Text = System.DateTime.Now.ToString();
    }

    protected void btnAdd_Click(object sender, System.EventArgs e)
    {
        DateTime dtime = System.DateTime.Now;
        try
        {
            dtime = System.DateTime.Parse(tbDateTime.Text);
        }
        catch
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "时间格式错误，请输入如“" + dtime.ToString() + "”的时间格式。");
            return;
        }

        string Title = tbTitle.Text.Trim();
        if (Title == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入标题。");

            return;
        }


        if (DAL.Tables.T_News.Insert(_User.ID, true, dtime, true, Title, true, ShoveEL._String.Compress(tbContent.Value), true, cbisShow.Checked, true, int.Parse(ViewState["NewType"].ToString()), true) < 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "新闻添加失败。");

            return;
        }

        this.Response.Redirect("AdminNews.aspx?NewType=" + ViewState["NewType"].ToString(), true);
    }
}
